void solve()
{
  int n, m;
  cin >> n >> m;

  vector<int> a(m + 1), c(n + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
    ans += a[i];
  }	

  auto id = [&](int x, int f) {
    return f * n + x;
  };

  int S = 400, T = 401;
  MaxFlowGraph flow(S, T, 500, 20000);
  for (int i = 1; i <= n; i++) {
    flow.addEdge(S, id(i, 1), 0);
    for (int j = 2; j <= 5; j++) {
      flow.addEdge(S, id(i, j), c[i]);
    }
  }
  int tot = 310;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      int f;
      cin >> f;
      for (int k = 1; k <= f; k++) {
        flow.addEdge(id(j, k), tot, inf);
      }
    }
    flow.addEdge(tot, T, a[i]);
    tot++;
  }
  cout << ans - flow.work() << '\n';
}